<!--       ProductTypemgr产品型号 -->
<template>
  <a-card
    :bordered="false"
    :body-style="{ 'padding-bottom': '0px' }"
    :style="{ margin: '6px', }"
  >
    <a-form
      ref="searchFormRef"
      name="advanced_search"
      :model="searchFormState"
      class="ant-advanced-search-form"
    >
      <a-row :gutter="24">
        <a-col :span="6">
          <a-form-item label="产品型号名称" name="PTName">
            <a-input
              v-model:value="searchFormState.PTName"
              placeholder="请输入产品型号名称"
              @keyup.enter="tableRef.refresh(true)"
            />
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="产品型号编号" name="PTNo">
            <a-input
              v-model:value="searchFormState.PTNo"
              placeholder="请输入产品型号编号"
              @keyup.enter="tableRef.refresh(true)"
            />
          </a-form-item>
        </a-col>
        <a-col :span="3">
          <a-form-item label="产品类型" name="PTID">
            <!-- <a-input
              v-model:value="searchFormState.PTID"
              placeholder="请输入产品类型ID"
              @keyup.enter="tableRef.refresh(true)"
            /> -->
            <a-select
              v-model:value="searchFormState.PTID"
              style="width: 100%"
              placeholder="请选择产品类型"
              :options="productType"
            ></a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-button
            class="mr10"
            type="primary"
            @click="tableRef.refresh(true)"
            v-show="hasRole(route.meta.RolePower)"
            >查询</a-button
          >
          <a-button
            class="xn-mg08"
            @click="reset"
            v-show="hasRole(route.meta.RolePower)"
            >重置</a-button
          >
        </a-col>
      </a-row>
    </a-form>
  </a-card>
  <a-card :bordered="false" :style="{ margin: '6px' }">
    <m-table
      :show-pagination="true"
      ref="tableRef"
      :columns="columns"
      :data="loadData"
      :alert="options.alert.show"
      bordered
      :row-key="(record) => record.ID"
      :tool-config="toolConfig"
      :row-selection="options.rowSelection"
      :scroll="{ x: 'max-content' }"
      class="default"
    >
      <template #operator>
        <a-space>
          <a-button
            type="primary"
            @click="infoFormRef.onOpen()"
            v-show="hasAddRole(route.meta.RolePower)"
          >
            <template #icon><plus-outlined /></template>
            新增
          </a-button>
        </a-space>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'TestCfg'">
          <a-button
            type="link"
            @click="showTestCfgModal(record.ID, record.TestCfg, 0)"
            style="padding-right: 10px"
            >查看</a-button
          >
          <a-button
            type="link"
            @click="showTestCfgModal(record.ID, record.TestCfg, 1)"
            v-show="hasEditRole(route.meta.RolePower)"
            >编辑</a-button
          >
        </template>
        <template v-if="column.dataIndex === 'AgeTimeLen'">
          <div style="display: flex; align-items: center">
            <span>{{ record.AgeTimeLen }}</span>
            <a-button
              type="link"
              @click="setAgeTime(record)"
              v-show="hasEditRole(route.meta.RolePower)"
              >修改</a-button
            >
          </div>
        </template>
        <template v-if="column.dataIndex === 'NumPerTuoPan'">
          <div
            style="display: flex; align-items: center; justify-content: center"
          >
            <span>{{ record.NumPerTuoPan }}</span>
            <a-button
              type="link"
              @click="setTuoPan(record)"
              v-show="hasEditRole(route.meta.RolePower)"
              >修改</a-button
            >
          </div>
        </template>
        <template v-if="column.dataIndex === 'AutoTestCfg'">
          <a-button
            type="link"
            @click="showAutoTestCfgModal(record.ID, record.AutoTestCfg, 0)"
            style="margin-right: 10px"
            >查看</a-button
          >
          <a-button
            type="link"
            @click="showAutoTestCfgModal(record.ID, record.AutoTestCfg, 1)"
            v-show="hasEditRole(route.meta.RolePower)"
            >编辑</a-button
          >
        </template>
        <template v-if="column.dataIndex === 'IsCheckFanKaOfPackage'">
          <a-switch
            :disabled="!hasEditRole(route.meta.RolePower)"
            :checked="record.IsCheckFanKaOfPackage === 1"
            @click="changeFanka($event, record)"
          />
        </template>
        <template v-if="column.dataIndex === 'IsCheckPassOfPackage'">
          <a-switch
            :disabled="!hasEditRole(route.meta.RolePower)"
            :checked="record.IsCheckPassOfPackage === 1"
            @click="changeCheckPassOfPackage($event, record)"
          />
        </template>
        <template v-if="column.dataIndex === 'IsCheckAgePassOfPackage'">
          <a-switch
            :disabled="!hasEditRole(route.meta.RolePower)"
            :checked="record.IsCheckAgePassOfPackage === 1"
            @click="changeCheckAgePassOfPackage($event, record)"
          ></a-switch>
        </template>
        <template v-if="column.dataIndex === 'action'">
          <a-space>
            <a-button
              type="link"
              @click="formRef.onOpen(record)"
              v-show="hasEditRole(route.meta.RolePower)"
              >修改基本信息</a-button
            >
            <a-divider type="vertical" />
            <!--   <a-divider type="vertical" />
            <a @click="infoFormRef.onOpen(record)">修改全部信息</a> -->

            <a-popconfirm
              placement="topRight"
              title="确定删除？"
              @confirm="deleteModule(record)"
              ok-text="确定"
              cancel-text="关闭"
            >
              <a-button
                type="link"
                danger
                size="small"
                v-if="hasDeleteRole(route.meta.RolePower)"
                >删除</a-button
              >
            </a-popconfirm>
          </a-space>
        </template>
      </template>
    </m-table>
  </a-card>
  <Form
    ref="formRef"
    @successful="tableRef.refresh(true)"
    :productType="formProdectType"
  />
  <InfoForm
    ref="infoFormRef"
    @successful="tableRef.refresh(true)"
    :productType="formProdectType"
  />
  <!-- 人工检测配置编辑弹窗 -->
  <a-modal class="default" v-model:open="editTest" title="人工检测配置">
    <template #footer>
      <a-button type="default" @click="editTest = false">取消</a-button>
      <a-button
        v-if="!editTestDisable"
        key="submit"
        type="primary"
        @click="editTestSubmit"
        >提交</a-button
      >
    </template>
    <a-form
      style="height: 500px; overflow: auto"
      ref="showTestFormRef"
      :model="editTestData"
      :rules="editTestDataRules"
      :label-col="{
        style: {
          width: '200px',
        },
      }"
      :wrapper-col="{ span: 8 }"
    >
      <a-form-item label="充电电压(V)最小值" name="VolMin">
        <a-input
          v-model:value="editTestData.VolMin"
          placeholder="请输入充电电压最小值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="充电电压(V)最大值" name="VolMax">
        <a-input
          v-model:value="editTestData.VolMax"
          placeholder="请输入充电电压最小值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="充电电流(A)最小值" name="CurMin">
        <a-input
          v-model:value="editTestData.CurMin"
          placeholder="请输入充电电压最小值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="充电电流(A)最大值" name="CurMax">
        <a-input
          v-model:value="editTestData.CurMax"
          placeholder="请输入充电电压最大值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CC电阻基准(Ω)" name="CCR">
        <a-input
          v-model:value="editTestData.CCR"
          placeholder="请输入CC电阻基准"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CC电阻误差(%)" name="CCRError">
        <a-input
          v-model:value="editTestData.CCRError"
          placeholder="请输入CC电阻误差"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="充电桩额定电流(A)" name="RatedCur">
        <a-input
          v-model:value="editTestData.RatedCur"
          placeholder="请输入充电桩额定电流"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CP峰值电压(V)" name="CPRealVol">
        <a-input
          v-model:value="editTestData.CPRealVol"
          placeholder="请输入CP峰值电压"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CP峰值电压误差(V)" name="CPRealVolError">
        <a-input
          v-model:value="editTestData.CPRealVolError"
          placeholder="请输入CP峰值电压误差"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CP频率最小值(Hz)" name="CPHzMin">
        <a-input
          v-model:value="editTestData.CPHzMin"
          placeholder="请输入CP频率最小值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="CP频率最大值(Hz)" name="CPHzMax">
        <a-input
          v-model:value="editTestData.CPHzMax"
          placeholder="请输入CP频率最大值"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="占空比(%)" name="CPEmpty">
        <a-input
          v-model:value="editTestData.CPEmpty"
          placeholder="请输入占空比"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
      <a-form-item label="占空比误差" name="CPEmptyError">
        <a-input
          v-model:value="editTestData.CPEmptyError"
          placeholder="请输入占空比误差"
          allow-clear
          :readonly="editTestDisable"
        />
      </a-form-item>
    </a-form>
  </a-modal>
  <!-- 自动检测配置编辑弹窗 -->
  <a-modal class="default" v-model:open="editAutoTest" title="自动检测配置">
    <template #footer>
      <a-button type="default" @click="editAutoTest = false">取消</a-button>
      <a-button
        v-if="!editAutoTestDisable"
        key="submit"
        type="primary"
        @click="editAutoTestSubmit"
        >提交</a-button
      >
    </template>
    <a-form
      style="height: 500px; overflow: auto"
      ref="autoTestFormRef"
      :model="autoTestData"
      :rules="autoTestDataRules"
      :label-col="{
        style: {
          width: '200px',
        },
      }"
      :wrapper-col="{ span: 8 }"
    >
      <a-form-item label="最大电压告警下限值(V)" name="MaxVolAlarmMin">
        <a-input
          v-model:value="autoTestData.MaxVolAlarmMin"
          placeholder="请输入最大电压告警下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label=" 最大电压告警上限值(V)" name="MaxVolAlarmMax">
        <a-input
          v-model:value="autoTestData.MaxVolAlarmMax"
          placeholder="请输入最大电压告警上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大电压合格下限值(V)" name="MaxVolPassMin">
        <a-input
          v-model:value="autoTestData.MaxVolPassMin"
          placeholder="最大电压合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大电压合格上限值(V)" name="MaxVolPasMax">
        <a-input
          v-model:value="autoTestData.MaxVolPasMax"
          placeholder="请输入最大电压合格上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小电压告警下限值(V)" name="MinVolAlarmMin">
        <a-input
          v-model:value="autoTestData.MinVolAlarmMin"
          placeholder="请输入最小电压告警下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小电压告警上限值(V)" name="MinVolAlarmMax">
        <a-input
          v-model:value="autoTestData.MinVolAlarmMax"
          placeholder="请输入最小电压告警上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小电压合格下限值(V)" name="MinVolPassMin">
        <a-input
          v-model:value="autoTestData.MinVolPassMin"
          placeholder="请输入最小电压合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小电压合格上限值(V)" name="MinVolPassMax">
        <a-input
          v-model:value="autoTestData.MinVolPassMax"
          placeholder="请输入最小电压合格上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大频率合格下限值(HZ)" name="MaxHzPassMin">
        <a-input
          v-model:value="autoTestData.MaxHzPassMin"
          placeholder="请输入最大频率合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大频率合格上限值(Hz)" name="MaxHzPassMax">
        <a-input
          v-model:value="autoTestData.MaxHzPassMax"
          placeholder="请输入最大频率合格上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大频率告警限值(Hz)" name="MaxHzAlarm">
        <a-input
          v-model:value="autoTestData.MaxHzAlarm"
          placeholder="请输入最大频率告警限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小频率合格下限值(HZ)" name="MinHzPassMin">
        <a-input
          v-model:value="autoTestData.MinHzPassMin"
          placeholder="请输入最小频率合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小频率合格上限值(HZ)" name="MinHzPassMax">
        <a-input
          v-model:value="autoTestData.MinHzPassMax"
          placeholder="请输入最小频率合格上限值(HZ)"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小频率告警限值(HZ)" name="MinHzAlarm">
        <a-input
          v-model:value="autoTestData.MinHzAlarm"
          placeholder="请输入最小频率告警限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大CP合格下限值(%)" name="MaxCPPassMin">
        <a-input
          v-model:value="autoTestData.MaxCPPassMin"
          placeholder="请输入最大CP合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大CP合格上限值(%)" name="MaxCPassMax">
        <a-input
          v-model:value="autoTestData.MaxCPassMax"
          placeholder="请输入最大CP合格上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最大CP告警值(%)" name="MaxCPAlarm">
        <a-input
          v-model:value="autoTestData.MaxCPAlarm"
          placeholder="请输入最大CP告警值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小CP合格下限值(%)" name="MinCPPassMin">
        <a-input
          v-model:value="autoTestData.MinCPPassMin"
          placeholder="请输入最小CP合格下限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小CP合格上限值(%)" name="MinCPPassMax">
        <a-input
          v-model:value="autoTestData.MinCPPassMax"
          placeholder="请输入最小CP合格上限值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
      <a-form-item label="最小CP告警值(%)" name="MinCPAlarm">
        <a-input
          v-model:value="autoTestData.MinCPAlarm"
          placeholder="请输入最小CP告警值"
          allow-clear
          :readonly="editAutoTestDisable"
        />
      </a-form-item>
    </a-form>
  </a-modal>
  <!-- 修改老化市场弹窗 -->
  <a-modal
    class="default"
    v-model:open="ageTimeModel"
    :title="`${ageTimeData.PMName}老化时长修改`"
    @ok="ageTimeSubmit"
  >
    <a-form
      ref="ageTimeFormRef"
      :model="ageTimeData"
      :rules="ageTimeDataRules"
      :label-col="{
        style: {
          width: '150px',
        },
      }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-item label="老化时长(s)" name="AgeTimeLen">
        <a-input
          v-model:value="ageTimeData.AgeTimeLen"
          placeholder="请输入老化时长"
          allow-clear
        />
      </a-form-item>
    </a-form>
  </a-modal>
  <!-- 修改托盘数量弹窗 -->
  <a-modal
    class="default"
    v-model:open="tuopanModel"
    :title="`${tuopanData.PMName}每托盘产品数量修改`"
    @ok="tuopanSubmit"
  >
    <a-form
      ref="tuopanFormRef"
      :model="tuopanData"
      :rules="tuopanDataRules"
      :label-col="{
        style: {
          width: '150px',
        },
      }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-item label="每托盘产品数量" name="NumPerTuoPan">
        <a-input
          v-model:value="tuopanData.NumPerTuoPan"
          placeholder="请输入每托盘产品数量"
          allow-clear
        />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
  
  <script setup name="productmodelmgr">
import Form from "./form.vue";
import InfoForm from "./infoForm.vue";
import { message } from "ant-design-vue";
import { required } from "@/utils/formRules";
import productmodelmgrApi from "@/api/productManagement/productmodelmgrApi";
import producttypemgrApi from "@/api/productManagement/producttypemgrApi";
import productbatchmgrApi from "@/api/productManagement/productbatchmgrApi";
import { onMounted } from "vue";
import { useRoute } from "vue-router";
import {
  transitionTime,
  getPreviousMonthDateTime,
  getCurrentDateTime,
} from "@/utils/time.js";
const route = useRoute();
const searchFormState = ref({
  ID: 0,
  PMName: "",
  PMNo: "",
  PTID: 0,
});
const formRef = ref();
const infoFormRef = ref();
const searchFormRef = ref();
const tableRef = ref();
const toolConfig = {
  refresh: true,
  height: true,
  columnSetting: false,
  striped: false,
};
const columns = [
  {
    title: "产品型号",
    dataIndex: "ID",
    align: "center",
    fixed: "left",
  },
  {
    title: "产品型号名称",
    dataIndex: "PMName",
    align: "center",
    fixed: "left",
  },
  {
    title: "产品型号编号",
    dataIndex: "PMNo",
    align: "center",
    fixed: "left",
  },
  {
    title: "产品类型ID",
    dataIndex: "PTID",
    align: "center",
  },
  {
    title: "产品型号说明",
    dataIndex: "PMDesp",
    align: "center",
  },
  {
    title: "老化时长(s)",
    dataIndex: "AgeTimeLen",
    align: "center",
  },
  {
    title: "人工检测配置",
    dataIndex: "TestCfg",
    align: "center",
  },
  {
    title: "自动检测配置",
    dataIndex: "AutoTestCfg",
    align: "center",
  },
  {
    title: "每托盘产品数量",
    dataIndex: "NumPerTuoPan",
    align: "center",
  },
  {
    title: "产品类型名称",
    dataIndex: "PTName",
    align: "center",
  },
  {
    title: "打包产品翻卡检验",
    dataIndex: "IsCheckFanKaOfPackage",
    align: "center",
  },
  {
    title: "打包产品合格检验",
    dataIndex: "IsCheckPassOfPackage",
    align: "center",
  },
  {
    title: "打包产品老化合格检验",
    dataIndex: "IsCheckAgePassOfPackage",
    align: "center",
  },
  {
    title: "操作",
    dataIndex: "action",
    align: "center",

    fixed: "right",
  },
];
// 列表选择配置
const options = {
  alert: {
    show: false,
    clear: () => {},
  },
};
const loadData = (parameter) => {
  return productmodelmgrApi
    .getProductModels(Object.assign(parameter, searchFormState.value))
    .then((res) => {
      return res;
    });
};
// 重置
const reset = () => {
  searchFormRef.value.resetFields();
  tableRef.value.refresh(true);
};
// 删除
const deleteModule = (record) => {
  let params = {
    ID: record.ID,
    PMName: record.PMName,
  };
  productmodelmgrApi
    .deleteProductModel(params)
    .then(() => {
      tableRef.value.refresh(true);
      message.success("删除成功");
    })
    .catch(() => {});
};

// 人工检测编辑弹窗显示隐藏控制
let editTest = ref(false);
// 弹窗是否可以编辑
let editTestDisable = ref(false);
// 编辑时候的保存数据
let editTestData = ref({});
let editTestDataID = ref();
const showTestCfgModal = (id, data, type) => {
  editTest.value = true;
  if (type === 0) {
    editTestDisable.value = true;
  } else if (type === 1) {
    editTestDisable.value = false;
  }

  editTestData.value = JSON.parse(data);
  delete editTestData.value["ID"];
  editTestDataID.value = id;
};
// 人工检测配置比编辑表单
const showTestFormRef = ref();
// 人工检测配置的表单校验
const editTestDataRules = {
  VolMin: [required("请输入充电电压最小值")],
  VolMax: [required("请输入充电电压最小值")],
  CurMin: [required("请输入充电电压最小值")],
  CurMax: [required("请输入充电电压最大值")],
  CCR: [required("请输入CC电阻基准")],
  CCRError: [required("请输入CC电阻误差")],
  RatedCur: [required("请输入充电桩额定电流")],
  CPRealVol: [required("请输入CP峰值电压")],
  CPRealVolError: [required("请输入CP峰值电压误差")],
  CPHzMin: [required("请输入CP频率最小值")],
  CPHzMax: [required("请输入CP频率最大值")],
  CPEmpty: [required("请输入占空比")],
  CPEmptyError: [required("请输入占空比误差")],
};
// 人工检测配置提交修改
const editTestSubmit = () => {
  // 表单校验
  showTestFormRef.value
    .validate()
    .then(() => {
      Object.keys(editTestData.value).forEach((key) => {
        editTestData.value[key] = parseFloat(editTestData.value[key]);
      });
      productmodelmgrApi
        .modifyProductModelTestCfg({
          ID: editTestDataID.value,
          TestCfg: JSON.stringify(editTestData.value),
        })
        .then(() => {
          editTest.value = false;
          tableRef.value.refresh(true);
          message.success("修改人工检测配置成功");
        });
    })
    .catch(() => {});
};

//控制弹窗是否展示
let editAutoTest = ref(false);
// 弹窗是否可以编辑
let editAutoTestDisable = ref(false);
let autoTestData = ref({});
let autoTestDataID = ref();
// 自动检测配置编辑弹窗显示隐藏控制
const showAutoTestCfgModal = (id, data, type) => {
  editAutoTest.value = true;
  if (type === 0) {
    editAutoTestDisable.value = true;
  } else if (type === 1) {
    editAutoTestDisable.value = false;
  }
  autoTestData.value = JSON.parse(data);
  delete autoTestData.value["ID"];
  autoTestDataID.value = id;
};
// 自动检测表单校验
const autoTestDataRules = {
  MaxVolAlarmMin: [required("请输入最大电压告警下限值")],
  MaxVolAlarmMax: [required("请输入最大电压告警上限值")],
  MaxVolPassMin: [required("最大电压合格下限值")],
  MaxVolPasMax: [required("请输入最大电压合格上限值")],
  MinVolAlarmMin: [required("请输入最小电压告警下限值")],
  MinVolAlarmMax: [required("请输入最小电压告警上限值")],
  MinVolPassMin: [required("请输入最小电压合格下限值")],
  MinVolPassMax: [required("请输入最小电压合格上限值")],
  MaxHzPassMin: [required("请输入最大频率合格下限值")],
  MaxHzPassMax: [required("请输入最大频率合格上限值")],
  MaxHzAlarm: [required("请输入最大频率告警限值")],
  MinHzPassMin: [required("请输入最小频率合格下限值")],
  MinHzPassMax: [required("请输入最小频率合格上限值")],
  MinHzAlarm: [required("请输入最小频率告警限值")],
  MaxCPPassMin: [required("请输入最大CP合格下限值")],
  MaxCPassMax: [required("请输入最大CP合格上限值")],
  MaxCPAlarm: [required("请输入最大CP告警值")],
  MinCPPassMin: [required("请输入最小CP合格下限值")],
  MinCPPassMax: [required("请输入最小CP合格上限值")],
  MinCPAlarm: [required("请输入最小CP告警值")],
};
// 自动检测配置表单
const autoTestFormRef = ref();
// 自动检测配置提交修改
const editAutoTestSubmit = () => {
  // 表单校验
  autoTestFormRef.value
    .validate()
    .then(() => {
      Object.keys(autoTestData.value).forEach((key) => {
        autoTestData.value[key] = parseFloat(autoTestData.value[key]);
      });

      productmodelmgrApi
        .modifyProductModelAutoTestCfg({
          ID: autoTestDataID.value,
          AutoTestCfg: JSON.stringify(autoTestData.value),
        })
        .then(() => {
          editAutoTest.value = false;
          tableRef.value.refresh(true);

          message.success("修改自动检测配置成功");
        });
    })
    .catch(() => {});
};
// 翻卡、合格、老化合格开关
const editSwitch = (ID, IsCheckFanKa, IsCheckPass, IsCheckAgePass) => {
  productmodelmgrApi
    .modifyProductModelIsCheckOfPackage({
      ID,
      IsCheckFanKa,
      IsCheckPass,
      IsCheckAgePass,
    })
    .then(() => {
      tableRef.value.refresh(true);

      message.success("修改成功");
    })
    .catch(() => {});
};
// 翻卡
const changeFanka = (bool, data) => {
  let code = bool ? 1 : 0;
  editSwitch(
    data.ID,
    code,
    data.IsCheckPassOfPackage,
    data.IsCheckAgePassOfPackage
  );
};
//合格
const changeCheckPassOfPackage = (bool, data) => {
  let code = bool ? 1 : 0;
  editSwitch(
    data.ID,
    data.IsCheckFanKaOfPackage,
    code,
    data.IsCheckAgePassOfPackage
  );
};
//老化合格
const changeCheckAgePassOfPackage = (bool, data) => {
  let code = bool ? 1 : 0;
  editSwitch(
    data.ID,
    data.IsCheckFanKaOfPackage,
    data.IsCheckPassOfPackage,
    code
  );
};
// 保存老化时长数据
let ageTimeData = ref({});
// 控制老化时长弹窗显示隐藏控制
let ageTimeModel = ref(false);
// 弹窗展示按钮
const setAgeTime = (data) => {
  ageTimeData.value = { ...data };
  ageTimeModel.value = true;
};
const ageTimeDataRules = {
  AgeTimeLen: [required("请输入老化时长")],
};
// 老化时长表单实例
const ageTimeFormRef = ref();
const ageTimeSubmit = () => {
  ageTimeFormRef.value
    .validate()
    .then(() => {
      productmodelmgrApi
        .modifyProductModelAgeTimeLen({
          ID: ageTimeData.value.ID,
          AgeTimeLen: parseFloat(ageTimeData.value.AgeTimeLen),
        })
        .then(() => {
          ageTimeModel.value = false;
          message.success("修改成功");
          tableRef.value.refresh();
        })
        .catch(() => {});
    })
    .catch((err) => {
      console.log(err);
    });
};
// 托盘数量修改弹窗
const tuopanModel = ref(false);
let tuopanData = ref({});
// 托盘
const setTuoPan = (data) => {
  tuopanData.value = { ...data };
  tuopanModel.value = true;
};
const tuopanDataRules = {
  NumPerTuoPan: [required("请输入每托盘产品数量")],
};
const tuopanFormRef = ref();
const tuopanSubmit = () => {
  tuopanFormRef.value
    .validate()
    .then(() => {
      productmodelmgrApi
        .modifyProductModelNumPerTuoPan({
          ID: tuopanData.value.ID,
          NumPerTuoPan: parseFloat(tuopanData.value.NumPerTuoPan),
        })
        .then(() => {
          tuopanModel.value = false;
          tableRef.value.refresh();
          message.success("修改成功");
        })
        .catch((error) => {});
    })
    .catch((err) => {
      console.log(err);
    });
};

// 产品类型下拉框数据

let productType = ref([]);
let formProdectType = ref([]);
const fetchProductType = () => {
  producttypemgrApi
    .getProductTypes({
      ID: 0,
      PTName: "",
      PTNo: "",
    })
    .then((res) => {
      productType.value = res.Data.map((i) => {
        return {
          label: i.ProductTypeName,
          value: i.ID,
        };
      });
      formProdectType.value = res.Data.map((i) => {
        return {
          label: i.ProductTypeName,
          value: i.ID,
        };
      });
      productType.value.unshift({
        label: "全部",
        value: 0,
      });
    });
};

onMounted(() => {
  fetchProductType();

});
</script>
<style lang="scss" scoped>
</style>
  